package com.ascainiao.paygame.controller;

import com.ascainiao.paygame.beans.ReturnData;
import com.ascainiao.paygame.mapper.ImageMapper;
import com.ascainiao.paygame.model.Image;
import com.ascainiao.paygame.utils.Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
public class ImageController {
    @Autowired
    private ImageMapper imageMapper;
    @GetMapping("/get_image_list")
    public ReturnData getImageList(){
        List<Image> list = imageMapper.selectList(null);
        return Tools.output("success","成功",list);
    }
    @GetMapping("/uploads/{date}/{imgName}")
    public void getPicture(@PathVariable String date,@PathVariable String imgName, HttpServletResponse response) throws IOException {
        Tools.readImage("/uploads/"+date+"/"+imgName,response);
    }
}
